package sistema.ecua911.interfaz;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.text.DateFormat;
import java.util.Date;
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.button.StandardButtonShaper;

/**
 *
 * @author pablo
 */
public class Menu extends javax.swing.JFrame {

    logueo interfazlogueo;
    VentanaUsuario ventanaUsuario;
    VentanaAdministracion ventanaAdministraccion;
    String cedulaUsuario;
    String tipo;
    hola panel_fondo = new hola("/sistema/ecua911/Imagenes/ecu.jpg");

    public Menu() {
        Date now = new Date();
        DateFormat df4 = DateFormat.getDateInstance(DateFormat.FULL);
        String s4 = df4.format(now);
        initComponents();
        setLocationRelativeTo(null);
        jLabel5.setText(s4);
        //panel_fondo = new hola("/sistema/ecua911/Imagenes/ecu.jpg");

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        btUsuario = new javax.swing.JButton();
        btadministrador = new javax.swing.JButton();
        jbcoperador = new javax.swing.JButton();
        jSeparator5 = new javax.swing.JToolBar.Separator();
        btRecibirLlamada = new javax.swing.JButton();
        jentidades = new javax.swing.JButton();
        btEstadisticas = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        jButton3 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jDesktopPane1 = panel_fondo;
        jToolBar2 = new javax.swing.JToolBar();
        btlogueo = new javax.swing.JButton();
        jToolBar3 = new javax.swing.JToolBar();
        jLabel1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        lbnombre = new javax.swing.JLabel();
        lbtipo = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jToolBar1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);

        btUsuario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sistema/ecua911/Imagenes/user.png"))); // NOI18N
        btUsuario.setText("    Usuarios    ");
        btUsuario.setFocusable(false);
        btUsuario.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btUsuario.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btUsuarioActionPerformed(evt);
            }
        });
        jToolBar1.add(btUsuario);

        btadministrador.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sistema/ecua911/Imagenes/Admin.png"))); // NOI18N
        btadministrador.setText("Administrador");
        btadministrador.setFocusable(false);
        btadministrador.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btadministrador.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btadministrador.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btadministradorActionPerformed(evt);
            }
        });
        jToolBar1.add(btadministrador);

        jbcoperador.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sistema/ecua911/Imagenes/folder_who.png"))); // NOI18N
        jbcoperador.setText("   Cooperador   ");
        jbcoperador.setFocusable(false);
        jbcoperador.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbcoperador.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jbcoperador);
        jToolBar1.add(jSeparator5);

        btRecibirLlamada.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sistema/ecua911/Imagenes/phone.png"))); // NOI18N
        btRecibirLlamada.setText("   Recibir Llamada   ");
        btRecibirLlamada.setFocusable(false);
        btRecibirLlamada.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btRecibirLlamada.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btRecibirLlamada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRecibirLlamadaActionPerformed(evt);
            }
        });
        jToolBar1.add(btRecibirLlamada);

        jentidades.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sistema/ecua911/Imagenes/images.jpg"))); // NOI18N
        jentidades.setText("   Entidades   ");
        jentidades.setFocusable(false);
        jentidades.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jentidades.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jentidades.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jentidadesActionPerformed(evt);
            }
        });
        jToolBar1.add(jentidades);

        btEstadisticas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sistema/ecua911/Imagenes/4cLLF.png"))); // NOI18N
        btEstadisticas.setText("Estadisticas");
        btEstadisticas.setFocusable(false);
        btEstadisticas.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btEstadisticas.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btEstadisticas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btEstadisticasActionPerformed(evt);
            }
        });
        jToolBar1.add(btEstadisticas);
        jToolBar1.add(jSeparator1);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sistema/ecua911/Imagenes/images (1).jpg"))); // NOI18N
        jButton3.setText("   Ayuda   ");
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton3);

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sistema/ecua911/Imagenes/salir.jpg"))); // NOI18N
        jButton5.setText("   Salir   ");
        jButton5.setFocusable(false);
        jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton5.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton5);

        javax.swing.GroupLayout jDesktopPane1Layout = new javax.swing.GroupLayout(jDesktopPane1);
        jDesktopPane1.setLayout(jDesktopPane1Layout);
        jDesktopPane1Layout.setHorizontalGroup(
            jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jDesktopPane1Layout.setVerticalGroup(
            jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 450, Short.MAX_VALUE)
        );

        jToolBar2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jToolBar2.setFloatable(false);
        jToolBar2.setRollover(true);

        btlogueo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sistema/ecua911/Imagenes/i_icon_profile.png"))); // NOI18N
        btlogueo.setText("   Iniciar   ");
        btlogueo.setFocusable(false);
        btlogueo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btlogueo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btlogueo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btlogueoActionPerformed(evt);
            }
        });
        jToolBar2.add(btlogueo);

        jToolBar3.setFloatable(false);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        jLabel1.setText("Nombre:");

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sistema/ecua911/Imagenes/contacts.png"))); // NOI18N

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        jLabel2.setText("Tipo:");

        lbnombre.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N

        lbtipo.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N

        jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sistema/ecua911/Imagenes/tear_off_calendar.png"))); // NOI18N

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel5.setText("Lunes 25 de marzo del 20014");

        jMenu1.setText("Archivo");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edicion");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 814, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jDesktopPane1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(lbnombre, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE)
                            .addComponent(lbtipo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(85, 85, 85)
                        .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 6, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(2, 2, 2)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jToolBar3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jDesktopPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lbnombre, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(lbtipo, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jSeparator2)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jToolBar3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btUsuarioActionPerformed
        //mostramos la venta del usuario
        if (!(ventanaUsuario instanceof VentanaUsuario)) {
            ventanaUsuario = new VentanaUsuario(0);
            CentrarVentanaInterna(ventanaUsuario);
        } else {
            CentrarVentanaInterna(ventanaUsuario);
            ventanaUsuario.cambiarPestana(0);
        }


    }//GEN-LAST:event_btUsuarioActionPerformed

    private void btRecibirLlamadaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRecibirLlamadaActionPerformed
        if (!(ventanaUsuario instanceof VentanaUsuario)) {
            ventanaUsuario = new VentanaUsuario(1);
            CentrarVentanaInterna(ventanaUsuario);
        } else {
             CentrarVentanaInterna(ventanaUsuario);
            ventanaUsuario.cambiarPestana(1);
        }
    }//GEN-LAST:event_btRecibirLlamadaActionPerformed

    private void btEstadisticasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEstadisticasActionPerformed
        GraficosEstadisticos graficos = new GraficosEstadisticos();
        
    }//GEN-LAST:event_btEstadisticasActionPerformed

    private void jentidadesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jentidadesActionPerformed
        if (!(ventanaUsuario instanceof VentanaUsuario)) {
            ventanaUsuario = new VentanaUsuario(2);
            CentrarVentanaInterna(ventanaUsuario);
        } else {
             CentrarVentanaInterna(ventanaUsuario);
            ventanaUsuario.cambiarPestana(2);
        }
    }//GEN-LAST:event_jentidadesActionPerformed

    private void btadministradorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btadministradorActionPerformed
        if (!(ventanaAdministraccion instanceof VentanaAdministracion)) {
            ventanaAdministraccion = new VentanaAdministracion();
            CentrarVentanaInterna(ventanaAdministraccion);
        }else{
           CentrarVentanaInterna(ventanaAdministraccion); 
          
        }
    }//GEN-LAST:event_btadministradorActionPerformed

    private void btlogueoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btlogueoActionPerformed
        interfazlogueo = new logueo(this);
        CentrarVentanaInterna(interfazlogueo);
    }//GEN-LAST:event_btlogueoActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jButton5ActionPerformed

    public static void main(String args[]) {
        Menu.setDefaultLookAndFeelDecorated(true); //que nos permite dejar a Substance la decoracion ( por asi decirlo) 
        SubstanceLookAndFeel.setSkin("org.jvnet.substance.skin.CremeSkin"); // Setencia que aplica el skin Creme de Substance
        Menu Ventana = new Menu(); //JFIngreso es la ventana del ejemplo anterior.
        Ventana.setVisible(true);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btEstadisticas;
    private javax.swing.JButton btRecibirLlamada;
    private javax.swing.JButton btUsuario;
    private javax.swing.JButton btadministrador;
    private javax.swing.JButton btlogueo;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton5;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator5;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JToolBar jToolBar2;
    private javax.swing.JToolBar jToolBar3;
    private javax.swing.JButton jbcoperador;
    private javax.swing.JButton jentidades;
    private javax.swing.JLabel lbnombre;
    private javax.swing.JLabel lbtipo;
    // End of variables declaration//GEN-END:variables

    public void CentrarVentanaInterna(JInternalFrame vent) {
        Dimension desktopSize = this.jDesktopPane1.getSize();
        Dimension jInternalFrameSize = vent.getSize();
        vent.setLocation((desktopSize.width - jInternalFrameSize.width) / 2,
                (desktopSize.height - jInternalFrameSize.height) / 2);
        this.jDesktopPane1.add(vent);
        vent.show();
    }

    public void AjustarVentanaInterna(JInternalFrame vent) {
        vent.setSize(this.jDesktopPane1.getSize());
        this.jDesktopPane1.add(vent);
        vent.show();
    }

    public void cargarUsuario(String cedula, String nombre, String tipo) {
        this.cedulaUsuario = cedula;
        this.tipo = tipo;

        lbnombre.setText(nombre);
        lbtipo.setText(this.tipo);
        validacionTipoUsuario(tipo);
    }

    public String getCedulaUsuario() {
        return cedulaUsuario;
    }

    public void setCedulaUsuario(String cedulaUsuario) {
        this.cedulaUsuario = cedulaUsuario;
    }

    public void validacionTipoUsuario(String tipo) {
        if (tipo.equals("Administrador")) {

        } else if (tipo.equals("Operador")) {
            jentidades.setVisible(false);
            this.btadministrador.setVisible(false);
            this.btEstadisticas.setVisible(false);
            // this.btUsuario.setVisible(false);
            this.jbcoperador.setVisible(false);

        }
    }

}

class hola extends JDesktopPane {

    private Image imagen;

    public hola() {
    }

    public hola(String nombreImagen) {
        if (nombreImagen != null) {
            imagen = new ImageIcon(
                    getClass().getResource(nombreImagen)
            ).getImage();
        }
    }

    public void setImagen(String nombreImagen) {
        if (nombreImagen != null) {
            imagen = new ImageIcon(
                    getClass().getResource(nombreImagen)
            ).getImage();
        } else {

            imagen = null;
        }

        repaint();
    }

    public void setImagen(Image nuevaImagen) {
        imagen = nuevaImagen;

        repaint();
    }

    @Override
    public void paint(Graphics g) {
        if (imagen != null) {
            g.drawImage(imagen, 0, 0, getWidth(), getHeight(),
                    this);
            setOpaque(false);
        } else {
            setOpaque(true);
        }

        super.paint(g);
    }

}
